/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - graphics/shaders
// Copyright( c) 2014.  All Rights Reserved
//
// File:		AEShaderConstantTable.inl
// Author:		Gianluca Belardelli
// Date:		30/01/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AESHADERCONSTANTTABLE_INL_
#define _AESHADERCONSTANTTABLE_INL_

AE_FORCEINLINE AEShaderConstantTable::AEShaderConstantTable( void ) 
{
	m_nEntryCount = 0;
	m_nFirstRegister = -1;
	m_lpEntry=AENULL;
	m_lpBuffer=AENULL;
}

AE_FORCEINLINE AEShaderConstantTable::~AEShaderConstantTable( void ) 
{
	Reset();
}

AE_FORCEINLINE void AEShaderConstantTable::Reset( void ) 
{
	m_nEntryCount = 0;
	m_nFirstRegister = -1;
	AE_SAFE_DELETE_ARRAY( m_lpEntry );
}

AE_FORCEINLINE AEINT32 AEShaderConstantTable::GetByteCount( void ) const 
{
	return m_nEntryCount*AECONSTANTBUFFER_REGISTER_SIZE;
}

AE_FORCEINLINE AEShaderConstantTable &AEShaderConstantTable::operator = ( const AEShaderConstantTable &other )
{
	AllocateEntries( other.m_nEntryCount );
	
	if( m_nEntryCount > 0 )
		memcpy( m_lpBuffer, other.m_lpBuffer, GetByteCount() );
	
	m_lpEntry = ((AEShaderConstantTable &)other).m_lpEntry; ///< no assignment operator!
	return *this;
}

AE_FORCEINLINE AEBOOL32 AEShaderConstantTable::operator == ( const AEShaderConstantTable &other ) const
{
	if( m_nFirstRegister != other.m_nFirstRegister )
		return AEFALSE;
	
	if( m_nEntryCount != other.m_nEntryCount )
		return AEFALSE;

	return memcmp( m_lpBuffer, other.m_lpBuffer, GetByteCount() ) == 0;
}

AE_FORCEINLINE AEBOOL32 AEShaderConstantTable::operator != ( const AEShaderConstantTable &other ) const 
{
	return !(*this == other);
}

#endif // _AESHADERCONSTANTTABLE_INL_
